const router = require('express').Router()
const { genAppToken, getAppList } = require('../token/app')
const { genUserToken, getUserList } = require('../token/user')

router.get('/user', (req, res) => {
  const { id, env } = req.query
  genUserToken({ id, env }).then(data => {
    res.send(data)
  })
})

router.get('/user/list', (req, res) => {
  const { env } = req.query
  getUserList(env).then(data => {
    res.send(data)
  })
})

router.get('/app', (req, res) => {
  const { id, env } = req.query
  genAppToken({ id, env }).then(data => {
    res.send(data)
  })
})

router.get('/app/list', (req, res) => {
  const { env } = req.query
  getAppList(env).then(data => {
    res.send(data)
  })
})

module.exports = router
